package de.karlNet.sshTray.gui.tableModels;

import java.util.ArrayList;
import java.util.List;

import javax.swing.table.AbstractTableModel;

import de.karlNet.sshTray.controller.TypeController;
import de.karlNet.sshTray.model.Type;

public class TypeTableModel extends AbstractTableModel{
	private List<Type> types = new ArrayList<Type>();

	public int getColumnCount() {
		return 2;
	}
	
	public Type getTypeAt(int row) {
		return this.types.get(row);
	}
	
	@Override
	public String getColumnName(int col) {
		switch(col) {
		case 0:
			return "Type Name";
		case 1:
			return "Script to Execute";
		default:
			throw new IllegalStateException("Undefined Column");
		}
	}

	public int getRowCount() {
		if(this.types.size()<=0) {
			return 1;
		}
		return this.types.size();
	}

	public Object getValueAt(int arg0, int arg1) {
		if(this.types.size()<=0) {
			switch (arg1) {
			case 0:
				return "-No hosts defined-";
			case 2:
			case 1:
				return "";
			default:
				throw new IllegalStateException("Undefined Column");
			}
		}
		Type con = this.types.get(arg0);
		switch (arg1) {
		case 0:
			return con.getTitle();
		case 1:
			return con.getCmdToExecute();
		default:
			throw new IllegalStateException("Undefined Column");
		}
	}

	public void refresh(List<Type> types) {
		this.types = types;
		this.fireTableDataChanged();
	}
	
	public TypeTableModel() {
//		this.types = typeController.readTypes();
	}
	
}
